import router from "./router";
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import {getToken} from "./ulits/token";
NProgress.configure({
  showSpinner: false
})

import store from "./store";

const whitelist = ['/login']


router.beforeEach(async (to, from, next) => {
  NProgress.start()
  if (getToken()){
    if (store.state.userInfo){
      next()
    }else {
      await store.dispatch('getInfo')
      await next(to.path)
    }
  }else {
    if (whitelist.includes(to.path)){
      next()
    }else {
      next('/login')
    }
  }
})

router.afterEach((to, from) => {
  NProgress.done()
})
